package 算法基础模板.chapter_01;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Scanner;

/**
 * 前缀和
 * 快速求区间的和
 * <p>
 * S[i] = a[1] + a[2] + a[i]
 * a[l] + ... + a[r] = s[r] - s[l - 1]
 * <p>
 * S[0] = 0
 *
 * @author Summerday
 */
public class PrefixSumT {

    static int n, m, l, r;
    static int[] nums;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        m = scanner.nextInt();
        nums = new int[n + 1];
        for (int i = 1; i < n + 1; i++) nums[i] = scanner.nextInt();
        System.out.println(Arrays.toString(nums));
        int[] s = new int[n + 1];

        for (int i = 1; i <= n; i++) {
            s[i] = s[i - 1] + nums[i];
        }
        while (m-- > 0) {
            l = scanner.nextInt();
            r = scanner.nextInt();
            int sum_l_r = s[r] - s[l - 1];
            System.out.println(String.format("%d->%d = %d", l, r, sum_l_r));
        }
    }
}
